package thread.zhou;

public class ChiHuo extends Thread {
    private Zhou zhou;

    public ChiHuo(String name, Zhou zhou) {
        super(name);
        this.zhou = zhou;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (zhou) {
                while (zhou.isFlag()) {
                    System.out.println(Thread.currentThread().getName()+"正在喝粥");
                    zhou.setFlag(false);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"吃完了，还是好饿啊");
                    System.out.println("没有粥，吃货正在等，好饿啊");
                    zhou.notifyAll();
                }
                try {
                    zhou.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}
